package com.bjsxt;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

public class BasicSocketClient {
    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter pw = null;
        //创建Socket对象，两个参数：1，服务端IP地址，2，服务端所监听的端口
         try {
           socket = new Socket("127.0.0.1",8888);
           pw = new PrintWriter(socket.getOutputStream());
           pw.println("服务端  你好"); //输入要输出的的内容
           pw.flush();//刷新
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
             if(pw !=null){
                 pw.close();
             }
             if(socket != null){
                 try {
                     socket.close();
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
         }


    }
}
